package TCP_chat;
//package com;

import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class MultiThreadHaoServer {
	public static void main(String[] args) throws Exception{
		ServerSocket svr=new ServerSocket(8888);
		System.out.println("anh dang doi em o port 9999");
		while(true){
			Socket soc=svr.accept();
			new Thread(new Processing(soc)).start();
			svr.close();
		}
	}
}
class Processing implements Runnable{
	private Socket soc;
	public Processing(Socket soc){
		this.soc=soc;
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		try{
			Scanner in=new Scanner(soc.getInputStream());
			String request=in.nextLine();
			String response="FROM SERVER: "+request.toUpperCase();
			System.out.println(request);
			
			PrintWriter out=new PrintWriter(soc.getOutputStream(), true);
			out.println(response);
			
			in.close();out.close();
		}
		catch(Exception e){
			e.getStackTrace();
		}
	}
}